//
//  FKHomeBannerCell.m
//  WanTao
//
//  Created by Macbook Pro on 2019/3/16.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKHomeBannerCell.h"
#import <SDCycleScrollView.h>
#import "FKCustomBannerCell.h"

@interface FKHomeBannerCell ()<SDCycleScrollViewDelegate>

@property (nonatomic, weak) SDCycleScrollView *bannerView;

@end

@implementation FKHomeBannerCell

- (void)setupSubviews
{
    [super setupSubviews];
    
    SDCycleScrollView *bannerView = [[SDCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, fkScreenW, fk_adjustW(188))];
    [self.contentView addSubview:bannerView];
    self.bannerView = bannerView;
    bannerView.delegate = self;
    bannerView.placeholderImage = kPlaceholder_2x1;
//    bannerView.currentPageDotColor = fkMainColor;
//    bannerView.pageDotColor = [UIColor whiteColor];
    bannerView.showPageControl = false;
    bannerView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
    bannerView.autoScrollTimeInterval = 2.0;
    
//    UIImageView *circleBgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"category_circle_bg"]];
//    [self.contentView addSubview:circleBgView];
//    
//    [circleBgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.bottom.right.offset(0);
//        make.height.offset(fk_adjustW(18));
//    }];
}

#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    
}

- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view
{
    return FKCustomBannerCell.class;
}

- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view
{
    FKCustomBannerCell *cell1 = cell;
    NSString *url = view.imageURLStringsGroup[index];
    [cell1.iconView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:kPlaceholder_2x1];
}

- (void)setData:(id)data
{
    [super setData:data];
//    self.bannerView.imageURLStringsGroup = @[@"", @"", @""];
    
    if ([data isKindOfClass:[NSArray class]]) {
        NSMutableArray *urls = [NSMutableArray array];
        for (NSDictionary *dict in data) {
//            NSString *url = fkFORMAT(@"%@%@", HostURL, dict[@"img"]);
            [urls addObject:dict[@"img"]];
        }
        self.bannerView.imageURLStringsGroup = urls;
    }
}

@end
